#include "01_Thread.hpp"
#include <stdio.h>  
#include <stdlib.h> // srand(), rand()
#include <time.h>   // time()

#include <memory>   // unique_ptr
#include <iostream>

using std::cout;
using std::endl;
using std::unique_ptr;

#define LOG(msg) \
    std::cout << "[" << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << "]" << msg << endl

class MyThread
:public Thread
{
public:
    MyThread() = default; // 基类有默认的构造函数可以空着
    ~MyThread() = default;

    MyThread(const MyThread&) = delete;
    MyThread operator= (const MyThread&) = delete;

    //void run override();  // 语法错误
    void run() override;    // 语法错误

};

//MyThread::~MyThread()
//{
//    pthread_join(_pthid, nullptr);
//}

void MyThread::run()
{
    LOG("");
    srand(time(nullptr));

    for(int i = 0; i < 10; i++)
    {
        int num = rand() % 100;
        printf("随机数：%d\n", num);
    }
}

void test()
{
    //1: Thread已经是指针类型，Thread* 是个二级指针
    //2: 智能指针的初始化是make_unique
    //unique_ptr<Thread*> mt = new MyThread();
    
    unique_ptr<Thread> mt(new MyThread());
    mt->start();
    mt->join();
}

int main()
{
    test();
    return 0;
}
